<?php
class FormProcessor_CreateCircle extends FormProcessor {
	protected $db = null;
	protected $circle = null;
	protected $user = null;
	public function __construct($db, $userid) {
		$this->db = $db;
		parent::__construct($this->db);
		$this->user = new DatabaseObject_User($this->db);
		$this->user->load($userid);
		
		$this->circle = new DatabaseObject_Circle($this->db);
	}
	
	public function process(Zend_Controller_Request_Abstract $request) {
		$this->circlename = $this->sanitize($request->getPost('circlename'));
		if (strlen($this->circlename) == 0) {
			$this->addError('circlename', '请输入圈子名称');
		} else {
			$this->circle->circlename = $this->circlename;
        }
        
        $this->description = $this->sanitize($request->getPost('description'));
        if (strlen($this->description) == 0) {
            $this->addError('description', '请输入圈子介绍');
        } else {
            $this->circle->description = $this->description;
        }
        
        $this->climit = $this->sanitize($request->getPost('limit'));
        if (strlen($this->climit) == 0) {
            $this->addError('climit', '身份验证信息有误');
        } else {
            $this->circle->climit = $this->climit;
        }
		
		
		if (!$this->hasError()) {
			$this->circle->dateline = time();
			$this->circle->userid = $this->user->getId();
			$this->circle->username = $this->user->username;
			$this->circle->save();
			$this->circle->addMember(0, 3);
		}
		return !$this->hasError();
	}
}
?>